<template>
  <el-container class="home-container">
    <!-- 头部 -->
    <el-header>
      <div>
        <!-- <img src="../assets/logo.png" alt="主页logo"> -->
        <span>数据管理系统</span>
      </div>
      <el-button type="info">退出</el-button>
    </el-header>
    <!-- 页面主体 -->
    <el-container>
      <!-- 侧部 -->
      <el-aside width="200px">
        <!-- 侧边栏菜单区 -->
        <div class="toggle-button" @click="toggleCollapse">|||</div>
        <el-menu
          background-color="#D3DCE6"
          text-color="#000"
          :unique-opened = "true"
          :collapse = "isCollapse"
          :collapse-transition = "false"
          :router = "true"
          :default-active = "activePath"
          >
          <!-- <el-menu-item  index="events" @click="saveNavState('events')">
            <template slot="title">
              <i class="el-icon-location"></i>
              <span>事件列表</span>
            </template>
          </el-menu-item > -->
          <el-menu-item index="events2" @click="saveNavState('events2')">
            <i class="el-icon-menu"></i>
            <span slot="title">事件列表</span>
          </el-menu-item>
          <el-menu-item index="knowledgeElements" @click="saveNavState('knowledgeElements')">
            <i class="el-icon-menu"></i>
            <span slot="title">知识元列表</span>
          </el-menu-item>
          <el-menu-item index="maps" @click="saveNavState('maps')">
            <i class="el-icon-menu"></i>
            <span slot="title">地图列表</span>
          </el-menu-item>
          <el-menu-item index="images" @click="saveNavState('images')">
            <i class="el-icon-menu"></i>
            <span slot="title">图片列表</span>
          </el-menu-item>
          <el-menu-item index="pdfs" @click="saveNavState('pdfs')">
            <i class="el-icon-menu"></i>
            <span slot="title">pdf列表</span>
          </el-menu-item>
          <el-menu-item index="times" @click="saveNavState('times')">
            <i class="el-icon-menu"></i>
            <span slot="title">时间列表</span>
          </el-menu-item>
          <el-menu-item index="addresses" @click="saveNavState('addresses')">
            <i class="el-icon-menu"></i>
            <span slot="title">地点列表</span>
          </el-menu-item>
          <el-menu-item index="peoples" @click="saveNavState('peoples')">
            <i class="el-icon-menu"></i>
            <span slot="title">人物列表</span>
          </el-menu-item>
        </el-menu>
      </el-aside>
      <!-- 主布局 -->
      <el-main>
        <!-- 子路由占位符 -->
        <router-view/> 
      </el-main>
    </el-container>
  </el-container>

</template>  

<script>
export default {
  data() {
    return {
      menuList: [],
      // 是否折叠
      isCollapse: false,
      // 被激活的连接地址
      activePath: ''
    }
  },
  created() {
    // this.getMenuList();
    this.activePath = window.sessionStorage.getItem("activePath");
  },
  methods:{
    async getMenuList() {
      const {data:res} = await this.$http.get("menus");
      if (res.meta.status !== 200) return this.$message.error(res.meta.msg);
      this.menuList = res.data;
      console.log(res);
    },
    // 左侧折叠与展开
    toggleCollapse() {
      this.isCollapse = !this.isCollapse;
    },
    // 保存菜单的激活状态
    saveNavState(activePath) {
      window.sessionStorage.setItem("activePath", activePath);
      this.activePath = activePath;
    }
  // logout() {
  //   window.sessionStorage.clear();
  //   this.$router.push("/login");
  // }
  }
}
</script>

<style lang="less" scoped>
  .home-container {
    height: 100%;
  }

  .el-header{
    background-color: #B3C0D1;
    color: #333;
    text-align: center;
    line-height: 60px;
    display: flex;
    justify-content: space-between;
    padding-left: 0;
    align-items: center;
    color: black;
    font-size: 20px;
    > div {
      display: flex;
      align-items: center;
      margin-left: 15px;
    }
  }
  
  .el-aside {
    background-color: #D3DCE6;
    color: #333;
    text-align: center;
    line-height: 200px;
  }
  
  .el-main {
    background-color: #E9EEF3;
    color: #333;
    text-align: center;
    line-height: 160px;
  }
  
  body > .el-container {
    margin-bottom: 40px;
  }
  
  .el-container:nth-child(5) .el-aside,
  .el-container:nth-child(6) .el-aside {
    line-height: 260px;
  }
  
  .el-container:nth-child(7) .el-aside {
    line-height: 320px;
  }

  .toggle-button {
    background-color: gray;
    font-size: 10px;
    line-height: 24px;
    color: #fff;
    text-align: center;
    letter-spacing: 0.2em;
    cursor: pointer;
  }

</style>


<!-- 原生 -->
<!-- <template>
  <div class="home">
    <img alt="Vue logo" src="../assets/logo.png">
    <HelloWorld msg="Welcome to Your Vue.js App"/>
  </div>
</template>

<script>
// @ is an alias to /src
import HelloWorld from '@/components/HelloWorld.vue'

export default {
  name: 'HomeView',
  components: {
    HelloWorld
  }
}
</script> -->



<!-- <el-submenu :index="item.id+''" v-for="item in menuList" :key="item.id">
  <template slot="title"> 
    <i class="el-icon-location"></i>  
    <span>{{item.authName}}</span>
  </template>
  <el-menu-item :index="subIntem.id+''" v-for="subItem in item.children" :key="subItem.id">
    <template slot="title">
      <i class="el-icon-location"></i>
      <span>{{subItem.authName}}</span>
    </template>
  </el-menu-item>
</el-submenu> -->